package com.definity.toolkit.ui.widget;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

import com.definity.toolkit.ui.Body;
import com.definity.toolkit.ui.layout.VisibleGridLayout;
import com.definity.toolkit.ui.widget.paint.Paint;

public class TablePanel extends JPanel implements Widget<TablePanel>, WidgetPaint<TablePanel> {

	private static final long serialVersionUID = 8315686562343846614L;
	private Paint paint;

	public TablePanel(int rows, int cols) {
		setLayout(new VisibleGridLayout(rows, cols));
	}
	
	@Override
	public String id() {
		return getName();
	}

	@Override
	public TablePanel id(String id) {
		setName(id);
		return this;
	}

	@Override
	public TablePanel properties(Body<TablePanel> body) {
		body.content(this);
		return this;
	}

	@Override
	public Color background() {
		return getBackground();
	}

	@Override
	public TablePanel background(Color background) {
		setBackground(background);
		return this;
	}

	@Override
	public Color foreground() {
		return getForeground();
	}

	@Override
	public TablePanel foreground(Color foreground) {
		setForeground(foreground);
		return this;
	}

	@Override
	public TablePanel size(int width, int height) {
		setSize(width, height);
		return this;
	}

	@Override
	public Font font() {
		return getFont();
	}

	@Override
	public TablePanel font(Font font) {
		setFont(font);
		return this;
	}
	
	public TablePanel add(Component c) {
		super.add(c);
		return this;
	}

	@Override
	public TablePanel paint(Paint paint) {
		this.paint = paint;
		return this;
	}
	
	@Override
	public void paintComponent(Graphics g) {
		if (paint != null)
			paint.paint((Graphics2D) g, this);
		super.paintComponent(g);
	}

}
